package lena;

import lib.Actor;
import lib.ActorAddress;
import lib.Message;
import java.awt.image.BufferedImage;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
 
public class DisplayerActor extends Actor{

	public DisplayerActor(ActorAddress superActor,ActorAddress myAddress) throws Exception{
		super(superActor,myAddress,"DisplayerActor");
		startActor();
	}
	
	protected boolean standardRoutine() throws Exception{
		this.standardRoutineIsUsed=false;	
		return true;
	}
	
	protected boolean handleMessage(Message msg) throws Exception{
		if (msg.getOperation().equals("Terminate")) {
			System.out.println("DisplayerActor will halt");
			return false;
		}
		
		System.out.println("DisplayerActor: image received");
		BufferedImage img = ((SentImage) msg.getContent()).getImage();
			
		JFrame frame = new JFrame();	
		frame.getContentPane().add(new JLabel(new ImageIcon(img)));	
		frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
				
		return true;
	}
}
